﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


#ifndef ApplicationInterface_h__
#define ApplicationInterface_h__

#include <string>
#include <functional>
#include <windows.h>
#include "../utility/MacroTool.h"
#include "../base/Size.h"

namespace SkyEngine2d
{

	using WinMsgFilter = std::function<bool(HWND hwnd, UINT msg, WPARAM wParam, LPARAM IParam)>;


	class IApplicationView;
	class IAppDelegate;

	/*!
	 \brief 应用程序实例的接口
	 \details
	*/
	class SGE_API IApplication
	{
	public:
		//! 开始运行程序
		/*!
		\return int
		*/
		virtual int run() = 0;

		//! 设置每帧的间隔
		/*!
		\param double interval 每帧的间隔
		\return void
		该API用来设置游戏的帧数，一般在 AppDelegte 中调用，默认帧数为 30  \a app->setPerFrameInterval(1/30.0f)
		*/
		virtual void setPerFrameInterval(double interval) = 0;

		//! 设置APP 的代理
		/*!
		\param AppDelegateInterface * app_delegate 代理
		\return void
		开发者需要继承代理的接口，并且重写其中的函数，以实现一下特殊的功能
		*/
		virtual void setAppDelegte(IAppDelegate* app_delegate) = 0;

		//! 获取应用程序的视图
		/*!
		\return IApplicationView*
		*/
		virtual IApplicationView* getAppView()const = 0;

		//! 设置windows 消息的过滤器
		/*!
		\param const WinMsgFilter & filter 消息过滤器
		\return void
		消息过滤器 允许 开发者有机会自定义的处理 windows 消息，如果不需要 引擎继续处理该消息，则返回 \a true，否则应该返回 \a false
		*/
		virtual void setWinMsgFilter(const WinMsgFilter& filter) = 0;

		//! 获取程序的根目录
		/*!
		\return std::wstring
		*/
		virtual const std::wstring& getAppDir() = 0;
	};


	/*!
	 \brief 应用程序的代理接口
	 \details 开发者需要重写这个接口
	*/
	class IAppDelegate
	{
	public:
		//! 初始化应用程序
		/*!
		\return bool  如果初始化成功，返回 true
		开发者可以在这里进行一下程序的初始化,如初始化场景，设置帧率等
		*/
		virtual bool appInit() = 0;

		//! 获取要创建的窗口大小
		/*!
		\return Size
		开发者可以重写这个函数，以提供适当的窗口大小
		*/
		virtual Size getWindowsSize() = 0;

		//! 当程序进入后台时调用次接口
		/*!
		\return void
		*/
		virtual void appEnterBackground() = 0;

		//! 程序进入前台时调用次接口
		/*!
		\return void
		*/
		virtual void appEnterForeground() = 0;

	};

}


#endif // ApplicationInterface_h__